package com.mxl.quartz.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.mxl.dao.cashorder.impl.GatewayReturnLogDaoImpl;
import com.mxl.dao.cashorder.model.GatewayReturnLog;
import com.mxl.quartz.JobMonitor;
import com.mxl.service.notify.http.HttpSender;

/**
 * 第一次立即通知商户不成功的订单再次通知 30s 一次 多线程通知
 * 
 * @author xianglin.mo
 * 
 */
public class RepairNotifyMemberJob implements JobMonitor {
	private static final Logger logger = LoggerFactory
			.getLogger(RepairNotifyMemberJob.class);
	private GatewayReturnLogDaoImpl gatewayReturnLogDao;

	private HttpSender httpSender;

	/**
	 * 查询第一次没有通知成功的订单 进行通知 通知次数达到10次以上者 暂停通知 等恢复后在通知 gatewayreturnlog 中
	 */
	public void run() {
		List<GatewayReturnLog> loglList = gatewayReturnLogDao
				.queryNotifyMemberFailOrder();
		if (loglList != null && !loglList.isEmpty()) {
			for (GatewayReturnLog log : loglList) {
				logger.info("RepairNotifyMemberJob notify member GatewayReturnLog id:"
						+ log.getId());
				if (log.getNotifytimes() >= 6) {
					log.setStatus(1);
				} else {
					GatewayReturnLog lognew = httpSender.postHttpData(log
							.getSubmitAddr());
					log.setLastupDate(lognew.getLastupDate());
					log.setNotifytimes(log.getNotifytimes() + 1);
					log.setStatusCode(lognew.getStatusCode());
					log.setResponseContent(lognew.getResponseContent());
				}
				gatewayReturnLogDao.update(log);
			}
		}
	}

	public GatewayReturnLogDaoImpl getGatewayReturnLogDao() {
		return gatewayReturnLogDao;
	}

	public void setGatewayReturnLogDao(
			GatewayReturnLogDaoImpl gatewayReturnLogDao) {
		this.gatewayReturnLogDao = gatewayReturnLogDao;
	}

	public HttpSender getHttpSender() {
		return httpSender;
	}

	public void setHttpSender(HttpSender httpSender) {
		this.httpSender = httpSender;
	}

}
